import { defineConfig, globalIgnores } from "eslint/config";
import jsEslint from "@eslint/js";
import tsEslint from "typescript-eslint";
import eslintPluginVue from "eslint-plugin-vue";
import globals from "globals";

/**
 * eslint 配置, 检查 js -> ts -> vue
 */

export default defineConfig([
  // 全局忽略
  globalIgnores([
    "**/dist/**",
    "**/node_modules/**",
    "**/coverage/**",
    "**/build/**",
    "**/out/**",
    "**/temp/**",
    "**/test/**",
    "**/tests/**",
    "**/test-results/**",
    "**/test-reports/**",
    "**/*.d.ts",
    "*.config.js"
  ]),
  // JavaScript 处理
  {
    files: ["**/*.js", "**/*.cjs", "**/*.mjs"],
    plugins: {},
    extends: [jsEslint.configs.recommended],
  },
  // TypeScript 处理
  {
    files: ["**/*.ts", "**/*.tsx"],
    // plugins: {
    //   "@typescript-eslint": tsEslint.plugin,
    // },
    extends: [tsEslint.configs.recommended],
  },
  {
    files: ["src/**/*.vue"],
    // plugins: {
    //   vue: eslintPluginVue,
    // },
    extends: [
      jsEslint.configs.recommended,
      ...tsEslint.configs.recommended,
      ...eslintPluginVue.configs['flat/recommended'],
    ],
    languageOptions: {
      parserOptions: {
        parser: {
          ts: tsEslint.parser
        },
        project: "./tsconfig.json",
        extraFileExtensions: [".vue"],
      },
      ecmaVersion: "latest",
      sourceType: "module",
      globals: {
        ...globals.browser,
      },
    },
  },
]);
